package buildings.office;

import buildings.exceptions.InvalidRoomsCountException;
import buildings.exceptions.InvalidSpaceAreaException;
import buildings.Space;
import buildings.dwelling.Flat;
import java.io.Serializable;

public class Office implements Space, Serializable, Cloneable {

    private float officeSquare;
    private int roomCount;
    private final float DEFAULT_OFFICE_SQUARE = 250;
    private final int DEFAULT_ROOM_COUNT = 1;

    public Office() {
        officeSquare = DEFAULT_OFFICE_SQUARE;
        roomCount = DEFAULT_ROOM_COUNT;
    }

    public Office(float officeSquare) {
        this.officeSquare = officeSquare;
        roomCount = DEFAULT_ROOM_COUNT;
    }

    public Office(int roomCount, float officeSquare) {
        if (officeSquare <= 0) {
            throw new InvalidSpaceAreaException();
        }
        if (roomCount <= 0) {
            throw new InvalidRoomsCountException();
        }
        this.officeSquare = officeSquare;
        this.roomCount = roomCount;
    }

    public float getSquare() {
        return officeSquare;
    }

    public int getRoomCount() {
        return roomCount;
    }

    public void setSquare(float officeSquare) {
        if (officeSquare <= 0) {
            throw new InvalidSpaceAreaException();
        }
        this.officeSquare = officeSquare;
    }

    public void setRoomCount(int roomCount) {
        if (roomCount <= 0) {
            throw new InvalidRoomsCountException();
        }
        this.roomCount = roomCount;
    }
    
    public String toString() {
        StringBuffer buf = new StringBuffer(this.getClass().getSimpleName() + 
                " (" + roomCount + ", " + officeSquare + ")");
        return buf.toString();
    }
    
    public boolean equals(Object obj) {
        return ((obj instanceof Office) 
                && ((Office)obj).getSquare() == officeSquare) 
                && (((Office)obj).getRoomCount() == roomCount);
    }
    
    public int hashCode() {
        return roomCount | Float.floatToIntBits(officeSquare);
    }
    
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
